package com.jumi.microservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.domain.Message;
import com.jumi.microservice.domain.vo.MessageUnreadVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface MessageMapper extends BaseMapper<Message>{

    @Select("SELECT " +
"           ifnull(sum(" +
"                CASE" +
"                WHEN system_type in (6,7,8,9)" +
"                THEN 1" +
"                ELSE 0" +
"                END" +
"            ),0) sys," +
"            ifnull(sum(" +
"                CASE system_type" +
"                WHEN 1" +
"                THEN 1" +
"                ELSE 0" +
"                END" +
"            ),0) fahuo," +
"            ifnull(sum(" +
"                CASE system_type" +
"                WHEN 2" +
"                THEN 1" +
"                ELSE 0" +
"                END" +
"            ),0) fukuan," +
"            ifnull(sum(" +
"                CASE system_type" +
"                WHEN 3" +
"                THEN 1" +
"                ELSE 0" +
"                END" +
"            ),0) yue," +
"            ifnull(sum(" +
"                CASE system_type" +
"                WHEN 4" +
"                THEN 1" +
"                ELSE 0" +
"                END" +
"            ),0) tui" +
"       FROM `auth_message` WHERE " +
"       message_type = '1'" +
"       AND read_member_id = 0" +
"       AND to_member_id = #{uids}")
    MessageUnreadVO selectUnread(@Param("uids") Long uids);
}
